<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="https://www.thymeleaf.org/">
<head th:replace="common/commonSrc :: commonHead(~{::title},~{::link},~{})">
    <title>管理登录</title>
    <link rel="stylesheet" href="/alert/message.css">
    <link rel="stylesheet" href="/loginFrom/loginFrom.css">
</head>
<body>
<div th:replace="common/commonSrc :: commonContent"></div>

<div class="htmleaf-container"
     style="width: 100%;height: 100%;margin: 0;padding: 0;animation: bgLoad 2s;animation-fill-mode: forwards;">
    <div id="wrapper" class="login-page" style="left: 2%;position:relative;padding-top: 7%">
        <div id="login_form" class="form">


            <form class="login-form" id="regFrom">
                <label for="userName"></label><input type="text" placeholder="用户名" id="userName" value="GoblinCwl"
                                                     disabled/>
                <label for="password"></label><input type="password" placeholder="密码" id="password"/>
                <button class="fromButton" id="login">登 录</button>
                <p class="fromMessage"><span>此页面仅腐竹使用</span></p>

            </form>

        </div>
    </div>
</div>


<nav th:replace="common/commonSrc :: commonNavFoot(~{})"></nav>
</body>
<div th:replace="common/commonSrc :: commonFoot(~{::script})">
    <script type="text/javascript" th:src="@{/alert/message.js}"></script>
    <script type="text/javascript">
        $(function () {
            $("#login").click(function () {
                check_login();
                return false;
            });
        });

        function check_login() {
            let password = $("#password");
            if (!/^[a-zA-Z]\w{5,17}$/.test(password.val())) {
                wrongMessage("密码错误", password);
                return;
            }
            $.ajax({
                type: 'POST',
                url: getRootPath() + 'admin/doLogin',
                data: {
                    password: password.val()
                },
                beforeSend: function () {
                    showModal(true);
                },
                complete: function () {
                    showModal();
                },
                success: function (res) {
                    res = JSON.parse(res);
                    if (res.code === "1") {
                        $.message({
                            message: '登陆成功'
                        });
                        window.location.href = getRootPath() + "admin/index";
                    } else {
                        let returnMessage = res.message;
                        let dhIndex = returnMessage.indexOf(",");
                        if (dhIndex !== -1) {
                            let showMessage = returnMessage.substring(0, dhIndex);
                            let pick$ = returnMessage.substring(dhIndex + 1, returnMessage.length);
                            wrongMessage(showMessage, $("#" + pick$));
                        } else {
                            wrongMessage(returnMessage, null);
                        }
                    }
                }
            });
        }

        function wrongMessage(message, clear$) {
            if (clear$ != null) {
                clear$.val("");
                clear$.focus();
            }
            $("#login_form").removeClass('shake_effect');
            setTimeout(function () {
                $("#login_form").addClass('shake_effect')
            }, 1);
            $.message({
                message: message,
                type: 'error'
            });
        }


    </script>
</div>
</html>